import { SAVE_CHSNNELS, ALL_CHANNELS, SAVE_ARTIVEL_LIST } from './constants'
const defaultState = {
  channels: [],
  allChannels: [],
  articles: {},
}
export default function HomeReducer(pre = defaultState, action) {
  switch (action.type) {
    case SAVE_CHSNNELS:
      return { ...pre, channels: action.data }
    case ALL_CHANNELS:
      return { ...pre, allChannels: action.data }
    case SAVE_ARTIVEL_LIST:
      return {
        ...pre,
        articles: {
          ...pre.articles,
          [action.data.channelId]: {
            timestamp: action.data.timestamp,
            list: action.data.loadMore
              ? [
                  ...pre.articles[action.data.channelId].list,
                  ...action.data.list,
                ]
              : action.data.list,
          },
        },
      }
    default:
      return pre
  }
}
